package com.sceneworker.extensions.sphere;

import com.acarter.propertytable.Property;
import com.acarter.propertytable.PropertySection;
import com.acarter.propertytable.propertyobject.FloatPropertyObject;
import com.acarter.propertytable.propertyobject.IntegerPropertyObject;
import com.jme.scene.Spatial;
import com.jme.scene.shape.Sphere;
import com.jme2utils.staticutils.GenericJMEUtils;
import com.sceneworker.extensions.trimesh.TriMeshPropertyPage;

public class SpherePropertyPage extends TriMeshPropertyPage {

	public SpherePropertyPage() {
		super();
		
		PropertySection		lcl_section = new PropertySection("Sphere");
		lcl_section.addProperty(new Property("Radius", new FloatPropertyObject()));
		lcl_section.addProperty(new Property("Radial Samples", new IntegerPropertyObject()));
		lcl_section.addProperty(new Property("Z Samples", new IntegerPropertyObject()));
		
		model.addPropertySection(0, lcl_section);
	}
	
	@Override
	protected void updateListeners(final Spatial spatial) {

		super.updateListeners(spatial);
		
		if(!(spatial instanceof Sphere)) {	return; }
		
		final	Sphere		lcl_sphere = (Sphere)spatial;
		
		FloatPropertyObject		lcl_radius = (FloatPropertyObject)model.getPropertyObject("Sphere", "Radius");
		lcl_radius.SetListener(new FloatPropertyObject.I_FloatPropertyObjectListener() {

			public float readValue() {
				return lcl_sphere.getRadius();
			}

			public void saveValue(float value) {
				GenericJMEUtils.updateGeometry(lcl_sphere, lcl_sphere.getCenter(), lcl_sphere.getZSamples(), lcl_sphere.getRadialSamples(), value);
			}
			
		});
		
		IntegerPropertyObject		lcl_radSamp = (IntegerPropertyObject)model.getPropertyObject("Sphere", "Radial Samples");
		lcl_radSamp.SetListener(new IntegerPropertyObject.I_IntegerPropertyObjectListener() {

			public int readValue() {
				return lcl_sphere.getRadialSamples();
			}

			public void saveValue(int value) {
				GenericJMEUtils.updateGeometry(lcl_sphere, lcl_sphere.getCenter(), lcl_sphere.getZSamples(), value, lcl_sphere.getRadius());
			}
			
		});
		
		IntegerPropertyObject		lcl_zSamp = (IntegerPropertyObject)model.getPropertyObject("Sphere", "Z Samples");
		lcl_zSamp.SetListener(new IntegerPropertyObject.I_IntegerPropertyObjectListener() {

			public int readValue() {
				return lcl_sphere.getZSamples();
			}

			public void saveValue(int value) {
				GenericJMEUtils.updateGeometry(lcl_sphere, lcl_sphere.getCenter(), value, lcl_sphere.getRadialSamples(), lcl_sphere.getRadius());
			}
			
		});
		
	}

}



